import java.awt.BufferCapabilities;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

public class OneShotServer {

	private void execute() throws IOException {
		int port = 8260;
		ServerSocket serversock = new ServerSocket(port);
		InetAddress monadresse = InetAddress.getLocalHost();
		trace("ici "+monadresse+"-"+ port+ " je suis en attente");
		Socket servicesocket = serversock.accept();
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				servicesocket.getInputStream()));
		PrintStream writer = new PrintStream(servicesocket.getOutputStream());
        String request = reader.readLine();
        if (request.toLowerCase().startsWith("quelle heure")){
        	 Date d = new Date();
        	 writer.println("il est "+d.toString());
        } else
        	 writer.println("je ne vous ai pas compris");
        trace (request);
        servicesocket.close();
        serversock.close();   
	}

	private void trace(String m) {
		System.out.print(m);	
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		OneShotServer server = new OneShotServer();
		try {
			server.execute();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
